<script setup>
import axios from 'axios';
import { ref } from 'vue';
import { useRouter } from 'vue-router'
import { useUrlStore } from '@/stores/url';
const UrlStore = useUrlStore()

import { check } from '@/apis/testAPI';

check().then(res=>{
    if(res.data.code==1200){
    //如果用户没有登录，指向动态登录界面
    var a = document.createElement('a');
    a.setAttribute('href', 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxdadd0122365919e8&scope=snsapi_userinfo&response_type=code&redirect_uri=http://175.178.62.164:61803/wxuser/getSignUpUserInfo?url=/question&expires_in=3600#wechat_redirect');
    a.setAttribute('target', '_blank');
    a.setAttribute('id', 'redict');
// 防止反复添加
    if(document.getElementById('redict')) {
	    document.body.removeChild(document.getElementById('redict'));
    }
    document.body.appendChild(a);
    a.click();
    }
}).catch(err=>{
    console.log(err);
})

const router = useRouter()

const content = ref('')

const formdata = new FormData()

  const handleSubmit = ()=>{
    // const urlParams = new URLSearchParams(window.location.search);
    // const value = urlParams.get('messageId');
    // console.log(value);
    // console.log(content._value);
    formdata.append('messageId',+UrlStore.query_id)
    formdata.append('content',content.value)
    axios({
      url:'http://175.178.62.164:61803/feedback/submit',
      method:'post',
      data:formdata,
      withCredentials: true
    }).then(result=>{
      if(result.data.code === 0){
        router.push('/feedBack-FB')
      }else{                               //提交失败,重复提交
            router.push('/feedBack-Rp');
        }
    })
  }

</script>

<template>
  <div class="bigBox">
    <h2>请描述您遇到的问题</h2>
    <div class="box"><textarea id="tx" v-model=content placeholder="请描述您遇到的问题" rows="20" maxlength="200"></textarea></div>
    <div class="buttonBox">
      <van-button plain type="primary" @click="" to="/choose">取消</van-button>
      <van-button type="primary" @click="handleSubmit">发送</van-button>
    </div>
  </div>
  
</template>

<style scoped>
.bigBox{
  background-image: linear-gradient(
    #4993fa,
    #9dc6ff,
    #a0e4f1,
    #f1fafb
  );
  height: 100vh;
}

h2{
  padding: 15px;
  margin: 0 25px;
  color:#fff ;
  text-shadow: 2px 2px 4px #000000;
}

.box{
  box-sizing: border-box;
  padding: 20px 20px;
  width: 325px;
  margin: 0 auto;
  border-radius: 20px;
  background-color: #fff;
  box-shadow: 7px 7px 10px #535353;
}

#tx{
  width: 100%;
  border: none;
  resize: none;
}

.van-button{
  width: 120px;
}
.buttonBox{
  margin: 30px 0;
  display: flex;
  justify-content: space-around;
}
</style>
